<?php
declare (strict_types = 1);

namespace app\beautiful\middleware;

//验证登录
use app\beautiful\model\member\MemberModel;

class MemberCheck
{
    use \app\BaseTrait;
    /**
     * 处理请求
     *  验证是否登录是否正确的中间件
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        if(empty($request->memberId)){
            return $this->error('您还没有登录账号，请先登录',100);
        }
        if(null === $member = MemberModel::find($request->memberId)){
            return $this->error('您还没有登录账号，请先登录',100);
        }
//        if($member->shop_id != $request->shopId){
//            return $this->error('您还没有登录账号，请先登录',100);
//        }
        $request->member = $member;
        return $next($request);
    }
}
